package com.xcjw.com.View;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;
import android.widget.Toolbar;

import com.xcjw.com.R;


/**
 *
 * @filename SimpleTool
 * @date on 2018/7/30 14:38
 *****/

@SuppressLint("NewApi")
public class SimpleTool extends Toolbar {
      /**
       * 左侧Title
       */
      private TextView mTxtLeftTitle;
      /**
       * 中间Title
       */
      private TextView mTxtMiddleTitle;
      /**
       * 右侧Title
       */
      private TextView mTxtRightTitle;

      public SimpleTool(Context context) {
            this(context,null);
      }

      public SimpleTool(Context context, AttributeSet attrs) {
            this(context, attrs,0);
      }

      @SuppressLint("NewApi")
      public SimpleTool(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
      }

      @Override
      protected void onFinishInflate() {
            super.onFinishInflate();
            mTxtLeftTitle = (TextView) findViewById(R.id.txt_left_title);
            mTxtMiddleTitle = (TextView) findViewById(R.id.txt_main_title);
            mTxtRightTitle = (TextView) findViewById(R.id.txt_right_title);
      }

      //设置中间title的内容
      public void setMainTitle(String text) {
            this.setTitle(" ");
            mTxtMiddleTitle.setVisibility(View.VISIBLE);
            mTxtMiddleTitle.setText(text);
      }

      //设置中间title的内容文字的颜色
      public void setMainTitleColor(int color) {
            mTxtMiddleTitle.setTextColor(color);
      }

      //设置title左边文字
      public void setLeftTitleText(String text) {
            mTxtLeftTitle.setVisibility(View.VISIBLE);
            mTxtLeftTitle.setText(text);
      }

      //设置title左边文字颜色
      public void setLeftTitleColor(int color) {
            mTxtLeftTitle.setTextColor(color);
      }

      //设置title左边图标
      public void setLeftTitleDrawable(int res) {
            Drawable dwLeft = ContextCompat.getDrawable(getContext(), res);
            dwLeft.setBounds(0, 0, dwLeft.getMinimumWidth(), dwLeft.getMinimumHeight());
            mTxtLeftTitle.setCompoundDrawables(dwLeft, null, null, null);
      }
      //设置title左边点击事件
      public void setLeftTitleClickListener(OnClickListener onClickListener){
            mTxtLeftTitle.setOnClickListener(onClickListener);
      }

      //设置title右边文字
      public void setRightTitleText(String text) {
            mTxtRightTitle.setVisibility(View.VISIBLE);
            mTxtRightTitle.setText(text);
      }

      //设置title右边文字颜色
      public void setRightTitleColor(int color) {
            mTxtRightTitle.setTextColor(color);
      }

      //设置title右边图标
      public void setRightTitleDrawable(int res) {
            Drawable dwRight = ContextCompat.getDrawable(getContext(), res);
            dwRight.setBounds(0, 0, dwRight.getMinimumWidth(), dwRight.getMinimumHeight());
            mTxtRightTitle.setCompoundDrawables(null, null, dwRight, null);
      }

      //设置title右边点击事件
      public void setRightTitleClickListener(OnClickListener onClickListener){
            mTxtRightTitle.setOnClickListener(onClickListener);
      }


}